package com.lagou.dao;

import com.lagou.pojo.Novel;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

@Mapper
@Component
public interface NovelDao {


    /*
       插入小说信息
    */
    @Insert("insert into novel(id,title,author,pic,content) values(#{id},#{title},#{author},#{pic},#{content})")
    public int insertNovel(@Param("id")Long id, @Param("title") String title, @Param("author") String author, @Param("pic") String pic, @Param("content") String content);

    /*
        根据id查询小说
     */
    @Select({"<script>"+
            "select * from novel n where n.id in " +
            "<foreach collection='novelIds' item='id' open='(' separator = ',' close=')'>#{id}</foreach>"
            +"</script>"})
    public List<Novel> findNovelByIds(@Param("novelIds") List<Long> novelIds);

    /*
        分页查询novel
     */
    @Select("select title,author,content from novel")
    public List<Novel> findNovelByPage();

    /*
        统计小说数量
     */
    @Select("select count(id) from novel")
    public Integer countNovel();
}
